package sd.settemmezzo.util;

import java.awt.Robot;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.awt.AWTException;

import sd.settemmezzo.register.RegistrationServer;

public class AutoStart {
	
	final static int NODI = RegistrationServer.MINPLAYERS;
	
	public static void main(String[] args) {
        
		int id;
		
        try {
            Robot robot = new Robot();
            
            for (int i=1; i <= NODI; i++) {
            	
            	robot.delay(200);
	            robot.mouseMove(625,93);
	            robot.mousePress(InputEvent.BUTTON1_MASK);
	            robot.mouseRelease(InputEvent.BUTTON1_MASK);
	            robot.delay(200);
	            robot.keyPress(KeyEvent.VK_1);
	            robot.keyRelease(KeyEvent.VK_1);
	            robot.delay(2600);
	            robot.keyPress(KeyEvent.VK_N);
	            robot.keyPress(KeyEvent.VK_O);
	            robot.keyPress(KeyEvent.VK_D);
	            robot.keyPress(KeyEvent.VK_O);
	            
	            switch (i) {
		            case 1:	 
		            	id = KeyEvent.VK_1; break;
		            case 2:  
		            	id = KeyEvent.VK_2; break;
		            case 3:	 
		            	id = KeyEvent.VK_3; break;
		            case 4:	 
		            	id = KeyEvent.VK_4; break;
		            case 5:	 
		            	id = KeyEvent.VK_5; break;
		            case 6:	 
		            	id = KeyEvent.VK_6; break;
		            case 7:	 
		            	id = KeyEvent.VK_7; break;
		            case 8:	 
		            	id = KeyEvent.VK_8; break;
		            default: 
		            	id = KeyEvent.VK_X;
	            }
	            
	            robot.keyPress(id);
	            robot.keyRelease(id);
	            robot.delay(200);
	            robot.mouseMove(640,420);
	            robot.delay(200);
	            robot.mousePress(InputEvent.BUTTON1_MASK);
	            robot.mouseRelease(InputEvent.BUTTON1_MASK);
	            
	            if (i < NODI) {
	            	robot.delay(2600);
		            robot.mouseMove(450, 15);
		            robot.mousePress(InputEvent.BUTTON1_MASK);
		            robot.mouseRelease(InputEvent.BUTTON1_MASK);
	            }
	            
            }
            
        } catch (AWTException e) {
            e.printStackTrace();
        }
    }

}
